package com.ruoyi.sl.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.sl.domain.SlWorkshop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.sl.mapper.SlGprocessMapper;
import com.ruoyi.sl.domain.SlGprocess;
import com.ruoyi.sl.service.ISlGprocessService;

/**
 * 大工序Service业务层处理
 * 
 * @author admin
 * @date 2024-06-05
 */
@Service
public class SlGprocessServiceImpl implements ISlGprocessService 
{
    @Autowired
    private SlGprocessMapper slGprocessMapper;

    /**
     * 查询大工序
     * 
     * @param gprocessId 大工序主键
     * @return 大工序
     */
    @Override
    public SlGprocess selectSlGprocessByGprocessId(Long gprocessId)
    {
        return slGprocessMapper.selectSlGprocessByGprocessId(gprocessId);
    }


    //根据部门查询大工序
    @Override
    public SlGprocess selectSlGprocessByDeptId(Long deptId){
        return slGprocessMapper.selectSlGprocessByDeptId(deptId);
    }
    /**
     * 校验大工序名是否存在
     *
     * @param slGprocess 大工序信息
     * @return
     */
    @Override
    public Boolean checkGprocessName(SlGprocess slGprocess){
        Long gprocessId = StringUtils.isNull(slGprocess.getGprocessId()) ? -1L : slGprocess.getGprocessId();
        SlGprocess gprocess = slGprocessMapper.selectSlGprocessByGprocessName(slGprocess);
        if (StringUtils.isNotNull(gprocess) && gprocess.getGprocessId().longValue() != gprocessId.longValue())
        {
            return false;
        }
        return true;
    }

    /**
     * 查询大工序列表
     * 
     * @param slGprocess 大工序
     * @return 大工序
     */
    @Override
    public List<SlGprocess> selectSlGprocessList(SlGprocess slGprocess)
    {
        return slGprocessMapper.selectSlGprocessList(slGprocess);
    }

    //根据车间ID查询所有大工序
    @Override
    public List<SlGprocess> selectSlGprocessListByWorkshopId(Long workshopId)
    {
        return slGprocessMapper.selectSlGprocessListByWorkshopId(workshopId);
    }

    /**
     * 根据车间ID查询车间下是否有子元素
     */
    public Boolean checkGprocessMemberNum(Long gprocessId){

        return slGprocessMapper.checkGprocessMemberNum(gprocessId) > 0?false:true;
    }

    /**
     * 新增大工序
     * 
     * @param slGprocess 大工序
     * @return 结果
     */
    @Override
    public int insertSlGprocess(SlGprocess slGprocess)
    {
        slGprocess.setCreateTime(DateUtils.getNowDate());
        return slGprocessMapper.insertSlGprocess(slGprocess);
    }

    /**
     * 修改大工序
     * 
     * @param slGprocess 大工序
     * @return 结果
     */
    @Override
    public int updateSlGprocess(SlGprocess slGprocess)
    {
        slGprocess.setUpdateTime(DateUtils.getNowDate());
        return slGprocessMapper.updateSlGprocess(slGprocess);
    }

    /**
     * 批量删除大工序
     * 
     * @param gprocessIds 需要删除的大工序主键
     * @return 结果
     */
    @Override
    public int deleteSlGprocessByGprocessIds(Long[] gprocessIds)
    {
        return slGprocessMapper.deleteSlGprocessByGprocessIds(gprocessIds);
    }

    /**
     * 删除大工序信息
     * 
     * @param gprocessId 大工序主键
     * @return 结果
     */
    @Override
    public int deleteSlGprocessByGprocessId(Long gprocessId)
    {
        return slGprocessMapper.deleteSlGprocessByGprocessId(gprocessId);
    }
}
